Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Jan 15, 2026

Before this PR, blanket implementations without constraints, such as impl<T> From<T> for T, were ignored, because they would give rise to too many calls with multiple call targets.

This PR changes that, and avoids multiple targets by only allowing blanket targets when no compatible non-blanket targets exist (we already had this check in place for method calls).

DCA looks good: Percentage of calls with call target increases by 1.5 % point and performance is more or less unchanged.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jan 15, 2026
@hvitved hvitved force-pushed the rust/type-inference-remove-blanket-constraint-restriction branch 6 times, most recently from 326464f to f7df602 Compare January 19, 2026 10:12
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Jan 19, 2026
@hvitved hvitved marked this pull request as ready for review January 19, 2026 10:12
@hvitved hvitved requested a review from a team as a code owner January 19, 2026 10:12
@hvitved hvitved requested review from Copilot and paldepind January 19, 2026 10:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the restriction that blanket implementations must have constraints, enabling resolution of calls like impl<T> From<T> for T. The change improves call target resolution by allowing blanket implementations when no compatible non-blanket targets exist, preventing ambiguous call targets through a specialization-aware disambiguation strategy.

Changes:

  • Modified type inference logic to handle blanket implementations without constraints
  • Added new predicate to check if arguments are NOT instantiations of function parameters
  • Extended blanket implementation constraint checking to handle unconstrained type parameters

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rust/ql/test/library-tests/type-inference/main.rs Updated test comment to expect call target resolution for blanket impl
rust/ql/test/library-tests/dataflow/local/main.rs Updated comments to reflect new flow summaries for reflexive From and Into implementations
rust/ql/test/library-tests/dataflow/local/inline-flow.expected Added new flow summaries for Into trait and updated MaD references to reflect new model numbering
rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll Added disambiguation logic to prefer non-blanket implementations and check for type parameter constraints
rust/ql/lib/codeql/rust/internal/typeinference/FunctionType.qll Renamed module and added predicate to detect non-matching type instantiations
rust/ql/lib/codeql/rust/internal/typeinference/FunctionOverloading.qll Extended sibling detection to handle multiple blanket implementations
rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll Extended constraint satisfaction to handle blanket impls without non-trivial constraints
rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll Added flow summary for reflexive From implementation that preserves values

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hvitved hvitved force-pushed the rust/type-inference-remove-blanket-constraint-restriction branch from f7df602 to fd309d6 Compare January 19, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant